package transactions.dq.master;

import transactions.dq.StringUtilForName;
import dinamica.*;

/**
 * @author anthony 2010-4-16
 * */
public class InsertMaster extends dinamica.audit.AuditableTransaction {
	public int service(Recordset inputParams) throws Throwable {
		// reuse superclass code
		int rc = super.service(inputParams);

		// get db object and save record with empty blob
		Db db = getDb();

		// 插入t_master
		String sqlInsertMaster = getResource("insert.sql");
		sqlInsertMaster = getSQL(sqlInsertMaster, inputParams);

		// 汉字名字转换成字母存放在master_chars
		String master_name = inputParams.getString("master_name");
		String charsStr = StringUtilForName.getFirstLetter(master_name);
		sqlInsertMaster = StringUtil.replace(sqlInsertMaster,
				"${master_chars}", charsStr);

		db.exec(sqlInsertMaster);

		// (1)插入t_master_detail
		String sqlInsertMasterDetail = getResource("insert_master-detail.sql");
		sqlInsertMasterDetail = getSQL(sqlInsertMasterDetail, inputParams);
		db.exec(sqlInsertMasterDetail);


		//录入后自动弹出窗口所需数据
		String sqlBack = getResource("back.sql");
		Recordset rs = db.get(getSQL(sqlBack, inputParams));
		publish("backconfig", rs);

		return rc;

	}

}
